<template>
    <div>
        <crumbs></crumbs>
        <h1>查询单个学生信息</h1>
        <el-form :inline="true" :model="formInline" class="demo-form-inline">
            <el-form-item>
                <el-input v-model="formInline.id" placeholder="请输入学号"></el-input>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="onSubmit">查询</el-button>
            </el-form-item>
        </el-form>
        <div v-show="this.formInline.flag">
            <div id="img">
                <div style="width:200px;height:200px">  
                    <img :src="formInline.stu_head_img" alt="" style="width:200px;height:200px">
                </div>
            </div>
            <el-table :data="formInline.result" style="width: 100%">
                <el-table-column prop="stu_id" label="学号" width="180"></el-table-column>
                <el-table-column prop="stu_name" label="姓名" width="180"></el-table-column>
                <el-table-column prop="stu_sex"  label="性别"></el-table-column>
                <el-table-column prop="stu_jg"  label="籍贯"></el-table-column>
                <el-table-column prop="stu_date" label="出生日期"></el-table-column>
                <el-table-column prop="stu_hobby" label="爱好"></el-table-column>
                <el-table-column prop="stu_gbf" label="男女朋友"></el-table-column>
            </el-table>
        </div>
    </div>
</template>

<script>
import {search_info} from '@/utils/studentsInfo.js';
import { Message } from 'element-ui';
    export default {
        data(){
            return{
                formInline: {
                    result:[],
                    id: '',
                    input:'',
                    stu_head_img:'',
                    stu_date:'',
                    flag:false
                },
            }
        },
        methods: {
            async onSubmit() {
                if(this.formInline.id == ''){
                    this.open4();
                }else{
                    this.formInline.flag = true;
                    let result = await search_info({
                        method:'get',
                        url:`/search_info/${this.formInline.id}`,
                        params:{},
                        headerType:'form'
                    })
                    console.log(result);
                    this.formInline.stu_head_img = result.stu_head_img;
                    result.stu_date = result.stu_date.slice(0,10);
                    console.log(result.stu_date);
                    this.formInline.result.push(result);
                    console.log(this.formInline.result);
                }
            },
            open4() {
                Message.error('请填写学号！');
            }
        }
    }
</script>

<style lang="scss" scoped>
#img{
    width: 100%;
    display:flex;
    justify-content: center;
    align-items: center;
    margin-bottom: 30px;
}
h1{
    font-size: 20px;
}
</style>